<template>
  <div>
    <van-form @submit="onSubmit">
      <van-field
        v-model="phone"
        name="电话"
        label="电话"
        placeholder="请输入电话"
        :rules="[{ required: true, message: '请填写用户名' }]"
      />
      <van-field
        v-model="password"
        type="password"
        name="密码"
        label="密码"
        placeholder="请输入密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <div style="margin: 16px">
        <van-button round block type="info" native-type="submit"
          >登录</van-button
        >
      </div>
    </van-form>
    <!-- <h3>{{ count }}</h3>
    <h3>{{ info }}</h3>
    <button @click="changeCount">改变count</button> -->
  </div>
</template>
 
<script>
import { mapActions, mapMutations, mapState } from "vuex";
import { login } from "../../api/api";

export default {
  computed: {
    ...mapState("count", ["count", "info"]),
  },
  data() {
    return {
      phone: "18701553442",
      password: "12121212",
    };
  },
  created() {
    // console.log(this.$store.state.count);
  },
  methods: {
    // ...mapMutations(['changeCount']),
    // ...mapMutations('count',['changeCount']),
    ...mapActions("user", ["getToken", "getUser"]),
    // 点击登录执行的函数
    async onSubmit(values) {
      const { phone, password } = this;
      await this.getToken({ phone, password }); // 调用仓库里面的action方法
      // 登录成功之后获取用户信息
      await this.getUser();
      this.$router.push("/home");
      // if (res.status == 200) {
      //   localStorage.setItem("token", res.data.data.token);
      //   this.$router.push("/home");
      // }
      // console.log("res", res);
      // console.log("输入框的值", values);
    },
  },
};
</script>

<style scoped>
</style>